package com.wmz.utils;

import com.wmz.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * @author wmz
 * @date 2024/7/8 21:00
 * @description AuthUtils
 */
public class AuthUtils {
    /**
     * 获取Security容器中登录的用户信息
     * @return
     */
    public static SecurityUser getLoginUser(){
        return (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取登录用户的ID
     * @return
     */
    public static Long getLoginUserId(){
        return getLoginUser().getUserId();
    }

    /**
     * 获取登录用户的权限集合
     * @return
     */
    public static Set<String> getPerms(){
        return getLoginUser().getPerms();
    }
}
